<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <link rel="stylesheet" href="./css/common.css">
    <style>
        .section-content {
            margin: 120px auto;
        }
    </style>
</head>

<body>
    <div id="container">
        <header>
            <h1>蜗牛学院学生管理系统</h1>
        </header>
        <main>
            <div class="section-content form-content">
                <div class="content">
                    <div class="content-info">
                        <h3>用户注册</h3>
                        <div>
                            <div>
                                <div class="content-row">
                                    <label>注册账号：</label>
                                    <input class="form-input" type="text" id="username">
                                </div>
                                <div class="content-row">
                                    <label>注册密码：</label>
                                    <input class="form-input" type="text" id="password">
                                </div>
                                <div class="content-row" style="margin-top: 50px;">
                                    <label></label>
                                    <button class="blue" id="registerBtn">注册</button>
                                    <a href="./login.html">已有账号，直接登录</a>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </main>
    </div>
    <script src="./js/jquery.min.js"></script>
    <script>
        $('#registerBtn').click(function() {
            const username = $('#username').val();
            const password = $('#password').val();

            $.ajax({
                url: '/users/register',
                type: 'POST',
                data: {
                    username, password
                },
                success(res) {
                    console.log(res);
                    if(res.code) {
                        alert('恭喜你，注册成功');
                    } else {
                        if(res.type == 'IS_EXIST') {
                            alert('抱歉，账号已存在，注册失败');
                        } else {
                            alert('抱歉，网络错误，注册失败，请重新注册');
                        }
                    }
                }
            })
        })

    </script>
</body>

</html>